package com.qq.集合.Collection.案例2_test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

//问题：
//1.存牌的容器定义成集合，因为大小不固定，存在增删操作
//2.牌定义成对象，这样可以给每张牌定义大小，方便比较大小进行排序
//3.玩家的牌类集合定义成TreeSet，制定好比较规则后，每次插入牌都会自动排序，不用调用sort更方便
//

public class douDiZhu_test {
	
	//1.定义一个静态集合储储存54张牌对象
	public static List<Cards>cards= new ArrayList<>();//比静态代码块先赋值
	//2.做牌：定义静态代码块初始化牌数据
	static{//只能用来赋值，东西还是要在外面定义
		
//		List<String> size = new ArrayList<>();
//		Collections.addAll(size,"3","4","5","6","7","8","9","10","J","Q","K","A","2");	
//		List<String>form = new ArrayList<>();
//		Collections.addAll(form, "♠","♥","♣","♦");
		
		//点数和花色的个数确定，类型确定，且没有增删操作不会改变，所以以定义成数组
		String[] size = {"3","4","5","6","7","8","9","10","J","Q","K","A","2"};
		String[] form = {"♠","♥","♣","♦"};
		
		//组合点数和花色
		int k = 0;
		for(String i : size){
			k++;
			for(String j : form){
				cards.add(new Cards(i + j,k));
					
			}
		}
		Collections.addAll(cards, new Cards("小🃏",++k),new Cards("大🃏",++k));
		
	}
	
	public static void main(String[] args) {
		//输出准备好的54张牌
		System.out.println(cards);
		//3.洗牌（打乱牌序）
		Collections.shuffle(cards);
		System.out.println(cards);
		
		//3.定义三个玩家并发牌
		List<Player> players = new ArrayList<>();
		
		Player p1 = new Player("赵",1000,1);
		Player p2 = new Player("何",2000,2);
		Player p3 = new Player("张",5000,3);
		players.add(p1);
		players.add(p2);
		players.add(p3);
		
		//给每个玩家发牌
		for(int i = 0;i < players.size();i++){
			
			int j = cards.size()-1;//牌的总数 （0开始所以要-1）
			int k = 17;//每个玩家的牌数
			while(players.get(i).getCard().size() < k){
				players.get(i).getCard().add(cards.remove(j));//根据索引删除元素，并返回被删除的元素
				j--;
			}
			
//			for(int j = cards.size()-1 ;players.get(i).getCard().size() < 51/3 ; j--){
//				players.get(i).getCard().add(cards.remove(j));
//				}
//				
//				break;
//			}
		}
		//4.给玩家的牌排序
		//TreeSet已经自动排好序
		
		//5.输出玩家的牌
		for(int i = 0;i < 3 ;i++){
			System.out.println(players.get(i).getName()+"的牌为："+players.get(i).getCard());
		}
		
		//5.地主
		Random r = new Random();
		int d = r.nextInt(2);
		System.out.println(players.get(d).getName()+"被选为地主,地主牌为："+cards);
		for(Cards a : cards){
			players.get(d).getCard().add(a);
			}	
		
		System.out.println(players.get(d).getCard());
		
		
		
		
		}
	
	
		
	
	

		
		
		
		
		
		
		

		
	}


